package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.Result;
import com.sky.service.AdminOrderService;
import com.sky.vo.OrderDetailVO;
import com.sky.vo.OrderSearchPageVO;
import com.sky.vo.OrderStatisticsVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
@RequiredArgsConstructor
@Slf4j
public class AdminOrderController {

    private final AdminOrderService adminOrderService;

    @GetMapping("/conditionSearch")
    public Result<?> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        OrderSearchPageVO orderSearchPageVO = adminOrderService.conditionSearch(ordersPageQueryDTO);
        return Result.success(orderSearchPageVO);
    }

    //各个状态的订单数量统计
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        OrderStatisticsVO orderStatisticsVO = adminOrderService.selectStatisticsCount();
        return Result.success(orderStatisticsVO);
    }

    @GetMapping("/details/{id}")
    public Result<?> selectDetailsById(@PathVariable Long id){
        OrderDetailVO orderDetailVO = adminOrderService.selectDetailsById(id);
        return Result.success(orderDetailVO);
    }

    //接单
    @PutMapping("/confirm")
    public Result<?> confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        adminOrderService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    @PutMapping("/rejection")
    public Result<?> rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        adminOrderService.rejection(ordersRejectionDTO);
        return Result.success();
    }


    @PutMapping("/cancel")
    public Result<?> cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        adminOrderService.cancel(ordersCancelDTO);
        return Result.success();
    }

    //派送
    @PutMapping("/delivery/{id}")
    public Result<?> delivery(@PathVariable Long id){
        adminOrderService.delivery(id);
        return Result.success();
    }

    @PutMapping("/complete/{id}")
    public Result<?> complete(@PathVariable Long id){
        adminOrderService.complete(id);
        return Result.success();
    }


}
